-- @owner:yangjian
-- @date:2024-4-3
-- @testpoint:1.去除大对象使用限制，测试大对象数据中包含中文、特殊字符等，合理报错

--清理环境
CREATE OR REPLACE FUNCTION f_opengauss_large_object_use_case0003_1()  
RETURNS VOID AS 
$$
BEGIN  
    BEGIN
    PERFORM lo_unlink(100);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(101);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
END;  
$$
LANGUAGE plpgsql;
/

select f_opengauss_large_object_use_case0003_1();

--环境准备
drop table if exists t_opengauss_large_object_use_case0003_1 cascade;
CREATE TABLE t_opengauss_large_object_use_case0003_1 (loid oid,fd int);
INSERT INTO t_opengauss_large_object_use_case0003_1 (loid) SELECT lo_create(100);

--step1:使用lo_put向大对象中插入中文;expect:成功
select lo_put(100,6,'测试数据');

--step2:查看大对象数据;expect:成功
select lo_get(100,6,16);

--step3:使用lo_put向大对象中插入特殊字符;expect:成功
select lo_put(100,30,'@@##');

--step4:查看大对象数据;expect:成功
select lo_get(100,30,16);

--step5:使用lowrite函数向大对象插入中文;expect:成功
INSERT INTO t_opengauss_large_object_use_case0003_1 (loid) SELECT lo_create(101);
begin;
SELECT lo_open(101,CAST(x'20000' | x'40000' AS integer));
select lowrite (0,'测试数据');
select loread (0,16);
select lo_close(0);
end;
/

--step6:使用lowrite函数向大对象插入特殊字符;expect:成功
begin;
SELECT lo_open(101,CAST(x'20000' | x'40000' AS integer));
select lowrite (0,'@@##');
select loread (0,16);
select lo_close(0);
end;
/

--清理环境
select lo_unlink(loid) from t_opengauss_large_object_use_case0003_1;
select f_opengauss_large_object_use_case0003_1();
drop table if exists t_opengauss_large_object_use_case0003_1 cascade;
drop function f_opengauss_large_object_use_case0003_1();

